import request from '../utils/request.js'

// 二维码登录涉及到 3 个接口,调用务必带上时间戳,防止缓存
// 二维码 key 生成
export function getQrKey () {
  return request({
    method: 'GET',
    url: '/login/qr/key',
    params: { timestamp: Date.now() }
  })
}

// 二维码生成接口
export function createQr (key, qrimg = true) {
  return request({
    method: 'GET',
    url: '/login/qr/create',
    params: { key, qrimg, timestamp: Date.now() }
  })
}
// 二维码状态监测
export const checkQr = (key) => {
  return request({
    method: 'GET',
    url: '/login/qr/check',
    params: { key, timestamp: Date.now() }
  })
}
// 发送验证码
export const sendCaptcha = (phone) => {
  return request({
    method: 'GET',
    url: '/captcha/sent',
    // params: { phone, timestamp: Date.now() }
    params: { phone }
  })
}
// 对验证码进行验证正确与否,似乎没有用,我直接登录的话,进不去不就代表验证码错了吗
// export const checkCaptcha = ({ phone, captcha }) => {
//   return request({
//     method: 'GET',
//     url: '/captcha/verify',
//     params: { phone, captcha, ctcode: 86, timestamp: Date.now() }
//   })
// }

// 登录,手机密码或手机验证码
export const login = ({ phone, md5Password, captcha }) => {
  return request({
    method: 'GET',
    url: '/login/cellphone',
    params: { phone, md5_password: md5Password, captcha }
  })
}

// 退出登录
export const logout = () => {
  return request({
    method: 'GET',
    url: '/logout'
  })
}
